// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HoldingAction.java

package com.boci.clientapp.holding.action;

import com.boci.clientapp.holding.HoldingScrPanel;
import com.boci.clientapp.holding.handler.HoldingHandler;
import com.boci.clientapp.holding.vo.HoldingDetailVO;
import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.MainPanel;
import com.boci.clientapp.trading.OptionScrPanel;
import com.boci.clientapp.trading.TradingScrPanel;
import com.boci.clientapp.trading.vo.TradingVO;
import com.boci.common.action.AbstractAction;
import com.boci.common.constant.RequestTypeConst;
import com.boci.common.util.AppException;
import com.boci.common.util.StringUtil;
import java.util.HashMap;
import java.util.logging.Logger;

public class HoldingAction extends AbstractAction
{

    public HoldingAction()
    {
    }

    private void doTrade(HashMap pInpMap, String pActionType)
        throws Exception
    {
        String strModName = "TRADING_MODULE";
        String strOptScrName = "OPTION_SCREEN";
        String strTrdScrName = "TRADING_SCREEN";
        OptionScrPanel optionScrPanel = (OptionScrPanel)appServ.getMainPanel().getPanel(strModName, strOptScrName);
        TradingScrPanel tradingScrPanel = (TradingScrPanel)(TradingScrPanel)appServ.getMainPanel().getPanel(strModName, strTrdScrName);
        TradingVO tradingVO = new TradingVO("", "");
        if(pActionType.equals("BUY"))
            tradingVO.setBuyOrSell("BUY");
        else
        if(pActionType.equals("SELL"))
            tradingVO.setBuyOrSell("SELL");
        else
            return;
        HoldingDetailVO holdingDetailVO = (HoldingDetailVO)pInpMap.get("SELECTED_VO");
        tradingVO.setSymbol(holdingDetailVO.getSymbol());
        tradingVO.setUnderlyingSymbol(holdingDetailVO.getUnderLyingSymbol());
        tradingVO.setOptionQty(holdingDetailVO.getVestedQty());
        String strMarketID = holdingDetailVO.getMarketId();
        if(strMarketID != null)
            strMarketID = strMarketID.toUpperCase();
        if(strMarketID.equals("OPTION"))
        {
            appServ.getMainPanel().showScreen(strModName, strOptScrName);
            optionScrPanel.chgOption("HK_OPTION");
            optionScrPanel.refresh(tradingVO);
        } else
        if(strMarketID.equals("USOPTION"))
        {
            appServ.getMainPanel().showScreen(strModName, strOptScrName);
            optionScrPanel.chgOption("US_OPTION");
            optionScrPanel.refresh(tradingVO);
        } else
        if(strMarketID.equals("HK"))
        {
            appServ.getMainPanel().showScreen(strModName, strTrdScrName);
            tradingScrPanel.chgMarket("HK_MARKET");
            tradingScrPanel.refresh(tradingVO);
        } else
        if(strMarketID.equals("US"))
        {
            appServ.getMainPanel().showScreen(strModName, strTrdScrName);
            tradingScrPanel.chgMarket("US_MARKET");
            tradingScrPanel.refresh(tradingVO);
        }
    }

    private void doRefreshHolding(HashMap pInpMap, String pActionType)
        throws Exception
    {
        if(pActionType.equals("GO"))
        {
            addExtraValues(pInpMap);
            String strReqType = RequestTypeConst.BOCI_HOLDING_URL;
            String strModName = "HOLDING_MODULE";
            String strScrName = "HOLDING_SCREEN";
            HoldingScrPanel holdingScrPanel = (HoldingScrPanel)appServ.getMainPanel().getPanel(strModName, strScrName);
            HoldingHandler holdingHandler = new HoldingHandler(strReqType);
            holdingScrPanel.refresh(holdingHandler.getAccountHolding(pInpMap));
            holdingScrPanel.showHoldingTable(holdingScrPanel.getSelection());
        }
    }

    private void addExtraValues(HashMap pInpMap)
    {
        pInpMap.put("selectAcct", appServ.getAccountNo());
    }

    public void doProcess(HashMap pInpMap, String pActionType)
    {
    	try{
	        appServ.setBusy(true);
	        if(pActionType.equals("GO"))
	            doRefreshHolding(pInpMap, pActionType);
	        else
	        if(pActionType.equals("BUY"))
	            doTrade(pInpMap, pActionType);
	        else
	        if(pActionType.equals("SELL"))
	            doTrade(pInpMap, pActionType);
    	}catch(AppException appEx){
            logger.info(StringUtil.formatException(appEx));
            if(pActionType.equals("GO"))
                showBlankHoldingTable();
            appServ.showErrorDialog(null, appEx.getMessage());    		
    	}catch(Exception sysEx){
            if(pActionType.equals("GO"))
                showBlankHoldingTable();
            logger.severe(StringUtil.formatException(sysEx));
            appServ.showSysErrDialog();
    	}finally{
    		appServ.setBusy(false);
    	}return;
    }

    private void showBlankHoldingTable()
    {
        String strModName = "HOLDING_MODULE";
        String strScrName = "HOLDING_SCREEN";
        HoldingScrPanel holdingScrPanel = (HoldingScrPanel)appServ.getMainPanel().getPanel(strModName, strScrName);
        holdingScrPanel.showHoldingTable(holdingScrPanel.getSelection());
        holdingScrPanel.refresh(null);
    }
}
